import { loginApi } from '@/api/user'
const state = {
  token: null
}
const mutations = {
  setToken (state, token) {
    state.token = token
  },
  removeToken (state, token) {
    state.token = null
  }
}
// token 来自于哪里呢 ===> 登录成功，登录接口提供
// 封装 引入 调用接口
// 在Vuex里调用接口 获取token,存储token
const actions = {
  async  loginAction (context, data) {
    const res = await loginApi(data)
    console.log(res)
    // 通过commit去触发mutations
    context.commit('setToken', res.data)
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
